import "package:flutter/material.dart";

class MyInfoPage extends StatelessWidget {
  var titles = ["我的消息", "阅读记录", "我的博客", "我的问答", "我的活动", "我的团队", "邀请好友"];
  var imagePaths = [
    "images/ic_my_message.png",
    "images/ic_my_blog.png",
    "images/ic_my_blog.png",
    "images/ic_my_question.png",
    "images/ic_discover_pos.png",
    "images/ic_my_team.png",
    "images/ic_my_recommend.png"
  ];
  var userAvatar;
  var userName;
  var icons = [];

  MyInfoPage() {
    for (var i = 0; i < imagePaths.length; i++) {
      icons.add(new Padding(
        padding: const EdgeInsets.fromLTRB(0.0, 0.0, 10.0, 0.0),
        child: new Image.asset(
          imagePaths[i],
          width: 30.0,
          height: 30.0,
        ),
      ));
    }
  }

  Widget renderRow(int i) {
    if (i == 0) {
      var avatarContainer = new Container(
        color: const Color(0xff63ca6c),
        height: 200.0,
        child: new Center(
          child: new Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              userAvatar == null
                  ? new Image.asset(
                      "images/ic_avatar_default.png",
                      width: 60.0,
                    )
                  : new Container(
                      width: 60.0,
                      height: 60.0,
                      decoration: new BoxDecoration(
                        shape: BoxShape.circle,
                        color: Colors.transparent,
                        image: new DecorationImage(
                            image: new NetworkImage(userAvatar),
                            fit: BoxFit.cover),
                        border: new Border.all(color: Colors.white, width: 1.0),
                      ),
                    ),
              new Text(
                userName == null ? "点击头像登录" : userName,
                style: new TextStyle(color: Colors.white, fontSize: 16.0),
              ),
            ],
          ),
        ),
      );
      return new GestureDetector(
        onTap: () {},
        child: avatarContainer,
      );
    }
    i -= 1;
    if (i.isOdd) {
      return new Divider(
        height: 1.0,
      );
    }
    i = i ~/ 2;
    String title = titles[i];
    var listItemContent = new Padding(
      padding: new EdgeInsets.fromLTRB(10.0, 15.0, 10.0, 15.0),
      child: new Row(
        children: <Widget>[
          icons[i],
          new Expanded(
            child: new Text(
              title,
              style: new TextStyle(fontSize: 16.0),
            ),
          ),
          new Image.asset(
            'images/ic_arrow_right.png',
            width: 30.0,
            height: 16.0,
          ),
        ],
      ),
    );
    return new InkWell(
      onTap: () {},
      child: listItemContent,
    );
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new ListView.builder(
      itemCount: titles.length * 2 + 1,
      itemBuilder: (context, index) => renderRow(index),
    );
  }
}
